package com.example.travel_front.Adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.travel_front.Model.DayDetail;
import com.example.travel_front.R;


import java.util.List;

public class DayDetailAdapter extends RecyclerView.Adapter<DayDetailAdapter.MyViewHolder> {

    private List<DayDetail> list;

    private Context mContext;
    public DayDetailAdapter(List<DayDetail> list) {
        this.list = list;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_day_detail, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        DayDetail dayDetail = list.get(position);
        Glide
            .with(mContext)
            .load(dayDetail.image_url)
            .centerCrop()
            .into(holder.thumb);
        holder.location.setText(dayDetail.location);
        holder.description.setText(dayDetail.description);
        holder.address.setText(dayDetail.address);
        holder.rating.setText(dayDetail.rating);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @SuppressLint("NotifyDataSetChanged")
    public void loadData(List<DayDetail> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        ImageView thumb;
        TextView location;
        TextView description;
        TextView address;
        TextView rating;
        public MyViewHolder(View itemView) {
            super(itemView);

            thumb = itemView.findViewById(R.id.thumb);
            location = itemView.findViewById(R.id.location);
            description = itemView.findViewById(R.id.description);
            address = itemView.findViewById(R.id.address);
            rating = itemView.findViewById(R.id.rating);
        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
    }

    public interface OnItemClickListener {
        void onItemClick(DayDetail DayDetail, int position);
    }
}